package com.yueka.service.Impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yueka.mapper.ActivityMapper;
import com.yueka.pojo.PageResult;
import com.yueka.pojo.entity.activity.Activity;
import com.yueka.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public PageResult<Activity> list(String activityName, String status, String isBanner, Integer page, Integer pageSize) {
        Page<Activity> pageList = activityMapper.selectPage(new Page<>(page, pageSize), Wrappers.lambdaQuery(Activity.class)
                .like(Activity::getActivityName, activityName)
                .eq(Activity::getStatus, status)
                .eq(Activity::getIsBanner, isBanner));
        return new PageResult<>(pageList.getTotal(), pageList.getRecords());
    }

    @Override
    public void delete(Integer id) {
        activityMapper.deleteById(id);
    }

    @Override
    public void insert(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activity.setCreateTime(LocalDateTime.now());
        activityMapper.insert(activity);
    }

    @Override
    public void update(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.updateById(activity);
    }

}
